package zcw.com.lib_leet_code;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by 朱城委 on 2021/7/12.<br><br>
 *
 * 存在重复元素
 */
public class Topic217 {

    public static void main(String[] args) {
        Topic217 instance = new Topic217();

        int[] array = new int[] {1,2,3,1};
        System.out.println(instance.containsDuplicate(array));

        array = new int[] {1,2,3,4};
        System.out.println(instance.containsDuplicate(array));

        array = new int[] {1,1,1,3,3,4,3,2,4,2};
        System.out.println(instance.containsDuplicate(array));
    }

    public boolean containsDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<>();

        for(int value : nums) {
            if(set.contains(value)) {
                return true;
            }

            set.add(value);
        }
        return false;
    }
}
